package com.clqteam.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.clqteam.model.Employee;
import com.clqteam.service.TreeService;
import com.clqteam.serviceimpl.TreeServiceImpl;

import net.sf.json.JSONArray;
/**
 * 
 * @author ZHX
 *
 */
public class TreeController extends HttpServlet{

	TreeService tSer = new TreeServiceImpl();
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF8");
		resp.setCharacterEncoding("UTF8");
		HttpSession session=req.getSession();
		Employee em=(Employee)session.getAttribute("employee");
		  int id=em.geteId();
		 int paid= tSer.findPaIdByeId(id);
		JSONArray js = tSer.findTreeByPaId(paid);
		PrintWriter pw = resp.getWriter();
		
		pw.write(js.toString());
		pw.flush();
		pw.close();
		
	}
	
}
